﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace threadState
{
    internal class Running : State
    {
        public Running()
        {
            StateName = "运行";
        }

        // 使线程从运行状态进入死亡状态
        public void Stop(Thread thread)
        {
            Console.Write($"ID 为 {thread.ThreadId} 的线程通过 Stop 操作已由");
            Console.Write($"{thread.CurrentState.StateName} 转为");
            thread.CurrentState = new Dead();
            Console.WriteLine($"{thread.CurrentState.StateName}\n");
        }

        // 使线程从运行状态进入阻塞状态
        public void Suspend(Thread thread)
        {
            Console.Write($"ID 为 {thread.ThreadId} 的线程通过 Suspend 操作已由");
            Console.Write($"{thread.CurrentState.StateName} 转为");
            thread.CurrentState = new Blocked();
            Console.WriteLine($"{thread.CurrentState.StateName}\n");
        }
    }
}
